package com.gaohe.web.controller.scp;

import java.util.List;

import com.gaohe.scp.domain.CsCollect;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.scp.domain.CsCarVisit;
import com.gaohe.scp.service.ICsCarVisitService;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.common.core.page.TableDataInfo;

/**
 * 车辆浏览Controller
 *
 * @author liuxiangyu
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/scp/visit")
public class CsCarVisitController extends BaseController
{
    @Autowired
    private ICsCarVisitService csCarVisitService;

    // 浏览量的新增或增加----牛相善
//    @PreAuthorize("@ss.hasPermi('scp:visit:add')")
    @Log(title = "浏览", businessType = BusinessType.INSERT)
    @PostMapping("/car/visit")
    public AjaxResult upsertVisit(@RequestBody CsCarVisit csCarVisit)
    {
        return AjaxResult.success(csCarVisitService.upsertVisit(csCarVisit));
    }


    // 收藏量的减少----牛相善
//    @PreAuthorize("@ss.hasPermi('scp:visit:edit')")
    @Log(title = "修改collect", businessType = BusinessType.UPDATE)
    @PutMapping("/car/{carId}")
    public AjaxResult decrementCollectByCarId(@PathVariable("carId") Long carId)
    {
        return toAjax(csCarVisitService.decrementCollectByCarId(carId));
    }


    // 收藏量的新增或增加----牛相善
//    @PreAuthorize("@ss.hasPermi('scp:visit:add')")
    @Log(title = "新增或修改", businessType = BusinessType.INSERT)
    @PostMapping("/car")
    public AjaxResult upsertCollect(@RequestBody CsCarVisit csCarVisit)
    {
        return toAjax(csCarVisitService.upsertCollect(csCarVisit));
    }

    /**
     * 查询车辆浏览列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsCarVisit csCarVisit)
    {
        startPage();
        List<CsCarVisit> list = csCarVisitService.selectCsCarVisitList(csCarVisit);
        return getDataTable(list);
    }

    /**
     * 导出车辆浏览列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:export')")
    @Log(title = "车辆浏览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsCarVisit csCarVisit)
    {
        List<CsCarVisit> list = csCarVisitService.selectCsCarVisitList(csCarVisit);
        ExcelUtil<CsCarVisit> util = new ExcelUtil<CsCarVisit>(CsCarVisit.class);
        util.exportExcel(response, list, "车辆浏览数据");
    }

    /**
     * 获取车辆浏览详细信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:query')")
    @GetMapping(value = "/{visitId}")
    public AjaxResult getInfo(@PathVariable("visitId") Long visitId)
    {
        return success(csCarVisitService.selectCsCarVisitByVisitId(visitId));
    }

    //根据车辆id查询浏览量和收藏量
//    @PreAuthorize("@ss.hasPermi('scp:visit:query')")
    @GetMapping(value = "/selectVisit/{carId}")
    public AjaxResult selectVisit(@PathVariable Long carId)
    {
        return success(csCarVisitService.selectCsCarVisitByCarId(carId));
    }

    /**
     * 新增车辆浏览
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:add')")
    @Log(title = "车辆浏览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsCarVisit csCarVisit)
    {
        return toAjax(csCarVisitService.insertCsCarVisit(csCarVisit));
    }

    /**
     * 修改车辆浏览
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:edit')")
    @Log(title = "车辆浏览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsCarVisit csCarVisit)
    {
        return toAjax(csCarVisitService.updateCsCarVisit(csCarVisit));
    }

    /**
     * 删除车辆浏览
     */
//    @PreAuthorize("@ss.hasPermi('scp:visit:remove')")
    @Log(title = "车辆浏览", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitIds}")
    public AjaxResult remove(@PathVariable Long[] visitIds)
    {
        return toAjax(csCarVisitService.deleteCsCarVisitByVisitIds(visitIds));
    }
}
